<%-- 
    Document   : customers
    Created on : Dec 5, 2011, 4:26:59 AM
    Author     : Michael
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<% if(session.getAttribute("LoggedIn")==null)
       {
    response.sendRedirect("index.html");
    return;
        }

%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript">
function row_custclick(txt)
{
    document.forms[txt].submit();
}

function row_mousehover(obj)
{
	obj.style.backgroundColor="#6699FF";
}

function row_mouseout(obj)
{
	obj.style.backgroundColor="";
}

function onpageload()
{
<% 
if(session.getAttribute("UserID")!=null) { %>
    window.top.location="profile.jsp"
    <% }  %>
        


}

</script>
</head>

<body onload="onpageload()">
<table width="500" border="0">
  <tr>
  <td align="center"><h2>All Customers</h2></td></tr>
      
   <tr>
    <td>
    <table width="500" border="1" >
    	<tr>
        <td width="167">First Name</td>
        <td width="167">Last Name</td>
        <td width="166">Email</td>
        </tr>
        <% 
            java.sql.Connection conn = null;
            try
            {
                conn = new DBClasses.GetConnection().getConnection();
                String query = "SELECT * FROM Customer ORDER BY Email";

                java.sql.Statement stmt = conn.createStatement();
                java.sql.ResultSet rs = stmt.executeQuery(query);

                int i=0;
                while(rs.next())
                {

        %>
        <tr onclick="row_custclick('<%="cust" + i %>')" onmouseout="row_mouseout(this)" onmouseover="row_mousehover(this)">
        <form name="<%="cust" + i %>" action="CustomerClicked.jsp" method="post">
        <input name="CUST" type="hidden" value="<%=rs.getInt("CustomerID")%>" />
        <td width="167"><%=rs.getString("Firstname")%></td>
        <td width="167"><%=rs.getString("Lastname")%></td>
        <td width="166"><%=rs.getString("Email")%></td>
        </form>
        </tr>
        <%
                        i++;
                   }
           }
           catch(Exception e)
           {
               e.printStackTrace();
           }

           finally
           {
               try{
               conn.close(); }
               catch(Exception e) {
                   e.printStackTrace();
               }
           }
        %>
    </table>
    </td>
  </tr>
</table>
</body>
</html>
